Sentry Memo
2021-02-08
Sentry Memo
platform: React, name: keicho-webclient
$ npm install --save @sentry/react @sentry/tracing
Next, import and initialize the Sentry module as early as possible, before initializing React:
code:ts
import React from "react";
import ReactDOM from "react-dom";
import * as Sentry from "@sentry/react";
import { Integrations } from "@sentry/tracing";
import App from "./App";
Sentry.init({
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: 1.0,
});
ReactDOM.render(<App />, document.getElementById("root"));
The above configuration captures both error and performance data. To reduce the volume of performance data captured, change tracesSampleRate to a value between 0 and 1.
先日のエラーを故意に再現してみる
code:ts
// @ts-ignore
https://gyazo.com/f3941c8b5f0b4a9ef3fc5900a8e0be19
https://gyazo.com/3b94acb65985631e3c423394a6f06b4d
開発サーバでやってるのにNew alert from keicho-webclient in productionってメールが届いてしまう
code:ts
Sentry.init({ ...
environment: process.env.NODE_ENV,
});
追加の情報を送る
Sentry.setContext("Info", { TalkID: TalkID });
https://gyazo.com/7d3f3633cd42fbe42aed83457fbc9a2c
Server side
$ pip install --upgrade sentry-sdk
Import and initialize the Sentry SDK early in your application's setup:
code:python
import sentry_sdk
sentry_sdk.init(
traces_sample_rate=1.0
)
code:python
@app.route('/')
def root():
1 / 0
return "OK"
ローカルのサーバでエラーを出してSentryへの報告がうまく動いてるか確認したいが、Flaskの開発モードだとエラーがキャッチされてデバッグ画面になってしまう
一旦FLASK_ENV=developmentを外す
逆に言えばこれがついてることでローカルサーバでのエラーは報告されない、普段はそれで良い
https://gyazo.com/e3b3a605f78047bb9224c5b5783bed5c
追加の情報を送る
sentry_sdk.set_context("info", {"talk": talk, "text": text})